//#define TEST_IO_READFILE
#ifdef TEST_IO_READFILE

#include "Win32.DateTime.h"
#include "Win32.IO.MapFile.h"

struct ReadFileResult
{
   public:
   DWORD StartTime;
   DWORD EndTime;
   TCHAR *FilePath;
   long FileSize;
   long AsciiChars;
   long NonPrintableChars;
   DWORD TotalMilliseconds;

   void PrintResults()
   {
      TotalMilliseconds = EndTime - StartTime;
      _tprintf(_T("%ld Milliseconds. (C++ Unmanaged)\n"),TotalMilliseconds);
   }
}  ;

class ReadFile
{
   public:
   static ReadFileResult ReadBigFile(TCHAR *fileName)
   {
      ReadFileResult r;
      r.StartTime = GetTickCount();

      Kif::Win32::IO::MapFile<char> f;
      f.Open(fileName);

      char *b = f.GetBuffer();
      char *l = b + f.GetBufferSize();

      long c=0, n=0, sz = f.GetBufferSize();
      while(b < l)
      {
         if ((*b >= ' ') && (*b <= 'z'))
            c++;
         else
            n++;
         b++;
      }

      r.EndTime = GetTickCount();
      r.FilePath = fileName;
      r.AsciiChars = c;
      r.NonPrintableChars = n;
      r.FileSize = sz;

      return r;
   }
}  ;

void main()
{
   TCHAR *fName = _T("D:/Downloads/Microsoft/VS80sp1-KB926601-X86-ENU.exe");
   int i,n = 10;
   double t=0, c=0;
   ReadFileResult r;
   for(i=0; i < n; i++)
   {
      r = ReadFile::ReadBigFile(fName);
      r.PrintResults();
      t += r.TotalMilliseconds;
      c++;
   }
   _tprintf(_T("%f Minutes.\n"),((t/1000.0)/60.0));
   _tprintf(_T("%f Avg. Milliseconds.\n"),(t/c));
}

#endif
